﻿using Volo.Abp.DependencyInjection;
using YAPACS.RisServer.Abstractions;
using YAPACS.RisServer.Interface.Imitate;
using YAPACS.Workflows;

namespace YAPACS.RisServer.Workflows.HomePage;

public class GetWorkLoadChartOption(IHomeChartService homeChartService) : WorkflowBase, IGetWorkLoadChartOption, ITransientDependency
{
    private readonly IHomeChartService _homeChartService = homeChartService;

    protected override async Task<WorkflowOutput> InvokeCoreAsync(WorkflowInput input)
    {
        if (input.GetValueOrDefault("query") is IQueryCollection query)
        {
            string chartType = query["granularity"].ToString(); // 用于决定前端要什么图表 
            string stage = query["stage"].ToString();
            string level = query["level"].ToString();
            DateTime startTime = Convert.ToDateTime(query["startTime"]);
            DateTime endTime = Convert.ToDateTime(query["endTime"]);
            string granularity = query["granularity"].ToString();
            AmisRes res = _homeChartService.GetWorkloadChartOption(stage, level, startTime, endTime, granularity, "");
            return await Task.FromResult(new WorkflowOutput
            {
                Success = true,
                Data = res
            });
        }
        return await Task.FromResult(new WorkflowOutput
        {
            Success = false,
            Error = "工作流输入参数错误",
            //Data = null
        });
    }
}
